package cn.biao.epic.sys.modular.consts.init;

import cn.biao.epic.base.consts.ConstantsContext;
import cn.biao.epic.sys.modular.consts.entity.EpicConfig;
import cn.biao.epic.sys.modular.consts.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Auther Uncle_Z
 * @date 2019/12/17 14:02
 * @Email:2545375@qq.com
 * @Descrition
 */
@Component
@Slf4j
public class EpicConfigInit implements CommandLineRunner {

    @Autowired
    private ConfigService configService;

    @Override
    public void run(String... args) throws Exception {
        List<EpicConfig> list = configService.list();

        if (list !=null && list.size()>0) {
            list.forEach(v -> ConstantsContext.putConstant(v.getCode(),v.getValue()));
            log.info("初始化常量" + list.size() + "条!");
        }
    }
}
